mui.init();
var seach = new Vue({
	el: '.mui-content',
	data: {
		list: [],
	},
	updated: function() {
		$(".hout").on("tap", function() {
			/*common.ajax("book/searchByName", {
				uid: common.uid,
				token: common.token,
				bookName: $(this).text()
			}, function(data) {
				if(data.code == 200) {
					common.open("../bookdetails/details.html", "../bookdetails/details.html", $(this).attr("uid"))
				} else if(data.code == 300) {
					mui.toast("该本书已经下架!!!")
				} else {
					mui.toast(data.message)
				}
			})*/
			console.log($(this).attr("uid"));
			common.open("../bookdetails/details.html", "../bookdetails/details.html", $(this).attr("uid"))
		})
	}
})
var get = JSON.parse(localStorage.getItem("seachtext")) || []
var temp = "";
var n = []
//
$(".seach_buttom").on("tap", function() {
	n = []
	temp = ""
	get = JSON.parse(localStorage.getItem("seachtext")) || [];
	console.log(get);
	var val = $(".seach_val").val();
	console.log(val);
	if(val == "") {
		mui.toast("请输入书籍名称")
		return
	}
	get.unshift(val)
	localStorage.setItem("seachtext", JSON.stringify(get))
	get = JSON.parse(localStorage.getItem("seachtext"))
	aa()
	localStorage.setItem("seach", $(".seach_val").val())
	common.open("searchdetails.html", 'searchdetails.html', "")
	$(".seach_val")[0].value = ""
})

aa()

function aa() {
	$.each(get, function(e, a) {
		if(n.indexOf(get[e]) == -1) {
			n.push(get[e])
		}
	})
	if(get == "") {
		$(".history").css("display", "none")
		$(".record").css("display", "none")
	} else {
		$(".history").css("display", "block")
		$(".record").css("display", "block")
	}
	$.each(n, function(e, a) {
		if(a.length > 10) {
			a = a.substring(0, 9) + "..."
		}
		temp += "<div>" + a + "</div>"
	})
	$(".record").html(temp)
}

$(".history").on("tap", "span", function() {
	localStorage.removeItem("seachtext")
	$(".record").css("display", "none")
	$(".history").css("display", "none")
})
//
$(".record").on("tap", 'div', function() {
	localStorage.setItem("seach", $(this).text())
	common.open("searchdetails.html", 'searchdetails.html', "")
})

common.ajax("book/bookHot", {
	uid: common.uid,
	token: common.token
}, function(data) {
	if(data.code = 200) {
		seach.list = data.data
		console.log(data)
	} else {
		mui.toast(data.message)
	}
})

var nativeWebview, imm, InputMethodManager;
var initNativeObjects = function() {
	if(mui.os.android) {
		var main = plus.android.runtimeMainActivity();
		var Context = plus.android.importClass("android.content.Context");
		InputMethodManager = plus.android.importClass("android.view.inputmethod.InputMethodManager");
		imm = main.getSystemService(Context.INPUT_METHOD_SERVICE);
	} else {
		nativeWebview = plus.webview.currentWebview().nativeInstanceObject();
	}
};
var showSoftInput = function() {
	if(mui.os.android) {
		imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
	} else {
		nativeWebview.plusCallMethod({
			"setKeyboardDisplayRequiresUserAction": false
		});
	}
	setTimeout(function() {
		//此处可写具体逻辑设置获取焦点的input
		var inputElem = document.querySelector('input');
		inputElem.focus();
	}, 10);
};
mui.plusReady(function() {
	initNativeObjects();
	showSoftInput();
});

window.addEventListener('refresh', function(e) { //执行刷新
	location.reload();
});